package com.lt.suangua.ui.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

public class MyPagerAdapter extends FragmentPagerAdapter {
    List<Fragment> fragmentList;
    public List<String>mTitles;

    //构造方法，方便之后赋值调用

    public MyPagerAdapter(FragmentManager fm, List<Fragment> fragmentList,List<String>titles){
        super(fm);
        this.fragmentList = fragmentList;
        this.mTitles=titles;
    }

    //根据Item的位置返回对应位置的Fragment，绑定item和Fragment

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    //设置item的数量

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {

        return  mTitles.size() != 0 ? mTitles.get(position) : "";
    }
}

